package com.foodplus.www.adapter.special;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.foodplus.www.bean.special.ArticleListBean;
import com.foodplus.www.bean.special.DatasBean;
import com.foodplus.www.foodplus.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/2 0002.
 */

public class SpecialChildAdapter extends RecyclerView.Adapter<SpecialChildAdapter.SpecialChildViewHolder> {

    private static final int SPECIAL_TYPE1 = 1;
    private static final int SPECIAL_TYPE2 = 2;
    private static final int SPECIAL_TYPE3 = 3;
    private static final int SPECIAL_TYPE4 = 4;
    private static final int SPECIAL_TYPE5 = 5;
    private static final int SPECIAL_TYPE6 = 6;


    private List<ArticleListBean> data;
    private Context context;
    private int  specialType;

    public SpecialChildAdapter(List<ArticleListBean> data, Context context, int specialType) {
        this.data = data;
        this.context = context;
        this.specialType = specialType;
    }

    @Override
    public int getItemViewType(int position) {
        return specialType;
    }

    @Override
    public SpecialChildViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        SpecialChildViewHolder specialChildViewHolder = null;
        switch (viewType) {
            case SPECIAL_TYPE1:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_video, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder1(view);
                break;
            case SPECIAL_TYPE2:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_list, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder2(view);
                break;
            case SPECIAL_TYPE3:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_knowledge, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder3(view);
                break;
            case SPECIAL_TYPE4:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_humanity, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder4(view);
                break;
            case SPECIAL_TYPE5:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_map, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder5(view);
                break;
            case SPECIAL_TYPE6:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_special_activity, parent, false);
                specialChildViewHolder = new SpecialChildViewHolder6(view);
                break;
        }
        return specialChildViewHolder;
    }

    @Override
    public void onBindViewHolder(SpecialChildViewHolder holder, int position) {
        switch (specialType){
            case SPECIAL_TYPE1:
                final SpecialChildViewHolder1 holder1 = (SpecialChildViewHolder1) holder;
                Glide.with(context).load(data.get(position).getArticle_image())
                        .placeholder(R.mipmap.bg_morentu)
                        .error(R.mipmap.bg_morentu)
                        .fitCenter()
                        .into(holder1.videoImage);
                holder1.videoLine.setText(R.string.line);
                holder1.videoTitle.setText(data.get(position).getArticle_title());
                holder1.videoAbstract.setText(data.get(position).getArticle_abstract());
                holder1.videoLength.setText(data.get(position).getVideo_length());
                break;
            case SPECIAL_TYPE2:
                final SpecialChildViewHolder2 holder2 = (SpecialChildViewHolder2) holder;
                Glide.with(context).load(data.get(position).getArticle_image())
                        .fitCenter()
                        .into(holder2.listImage);
                holder2.listAbstract.setText(data.get(position).getArticle_abstract());
                holder2.listTitle.setText(data.get(position).getArticle_title());
                holder2.listOrigin.setText("FROM"+data.get(position).getArticle_origin());
                holder2.listTop.setText("TOP"+data.get(position).getTop());
                break;
            case SPECIAL_TYPE3:
                final SpecialChildViewHolder3 holder3 = (SpecialChildViewHolder3) holder;
                Glide.with(context).load(data.get(position).getArticle_image())
                        .placeholder(R.mipmap.bg_morentu)
                        .error(R.mipmap.bg_morentu)
                        .fitCenter()
                        .into(holder3.knowledgeImage);
                holder3.knowledgeLine.setText(R.string.line);
                holder3.knowledgeTitle.setText(data.get(position).getArticle_title());
                holder3.knowledgeAbstract.setText(data.get(position).getArticle_abstract());
                holder3.knowledgeQa.setText("Q&A");
                break;
            case SPECIAL_TYPE4:
                final SpecialChildViewHolder4 holder4 = (SpecialChildViewHolder4) holder;
                Glide.with(context).load(data.get(position).getArticle_image())
                        .placeholder(R.mipmap.bg_morentu)
                        .error(R.mipmap.bg_morentu)
                        .fitCenter()
                        .into(holder4.humanityImage);
                holder4.humanityLine.setText(R.string.line);
                holder4.humanityTitle.setText(data.get(position).getArticle_title());
                holder4.humanityAbstract.setText(data.get(position).getArticle_abstract());
                break;
            case SPECIAL_TYPE5:
                final SpecialChildViewHolder5 holder5 = (SpecialChildViewHolder5) holder;
                Glide.with(context).load(data.get(position).getArticle_image())
                        .placeholder(R.mipmap.bg_morentu)
                        .error(R.mipmap.bg_morentu)
                        .fitCenter()
                        .into(holder5.mapImage);
                holder5.mapLine.setText(R.string.line);
                holder5.mapTitle.setText(data.get(position).getArticle_title());
                holder5.mapAbstract.setText(data.get(position).getArticle_abstract());
                break;
//            case SPECIAL_TYPE6:
//                final SpecialChildViewHolder6 holder6 = (SpecialChildViewHolder6) holder;
//                break;
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class SpecialChildViewHolder extends RecyclerView.ViewHolder {
        public SpecialChildViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class SpecialChildViewHolder1 extends SpecialChildViewHolder {
        @BindView(R.id.video_image)
        ImageView videoImage;
        @BindView(R.id.video_length)
        TextView videoLength;
        @BindView(R.id.video_line)
        TextView videoLine;
        @BindView(R.id.video_title)
        TextView videoTitle;
        @BindView(R.id.video_abstract)
        TextView videoAbstract;

        public SpecialChildViewHolder1(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class SpecialChildViewHolder2 extends SpecialChildViewHolder {
        @BindView(R.id.list_image)
        ImageView listImage;
        @BindView(R.id.list_abstract)
        TextView listAbstract;
        @BindView(R.id.list_title)
        TextView listTitle;
        @BindView(R.id.list_origin)
        TextView listOrigin;
        @BindView(R.id.list_top)
        TextView listTop;

        public SpecialChildViewHolder2(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class SpecialChildViewHolder3 extends SpecialChildViewHolder {
        @BindView(R.id.knowledge_image)
        ImageView knowledgeImage;
        @BindView(R.id.knowledge_qa)
        TextView knowledgeQa;
        @BindView(R.id.knowledge_line)
        TextView knowledgeLine;
        @BindView(R.id.knowledge_title)
        TextView knowledgeTitle;
        @BindView(R.id.knowledge_abstract)
        TextView knowledgeAbstract;

        public SpecialChildViewHolder3(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class SpecialChildViewHolder4 extends SpecialChildViewHolder {
        @BindView(R.id.humanity_image)
        ImageView humanityImage;
        @BindView(R.id.humanity_line)
        TextView humanityLine;
        @BindView(R.id.humanity_title)
        TextView humanityTitle;
        @BindView(R.id.humanity_abstract)
        TextView humanityAbstract;

        public SpecialChildViewHolder4(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class SpecialChildViewHolder5 extends SpecialChildViewHolder {
        @BindView(R.id.map_line)
        TextView mapLine;
        @BindView(R.id.map_title)
        TextView mapTitle;
        @BindView(R.id.map_abstract)
        TextView mapAbstract;
        @BindView(R.id.map_image)
        ImageView mapImage;

        public SpecialChildViewHolder5(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class SpecialChildViewHolder6 extends SpecialChildViewHolder {
        @BindView(R.id.activity_image)
        ImageView activityImage;
        @BindView(R.id.activity_end)
        TextView activityEnd;
        @BindView(R.id.activity_name)
        TextView activityName;
        @BindView(R.id.activity_virtual)
        TextView activityVirtual;
        public SpecialChildViewHolder6(View itemView) {
            super(itemView);
        }
    }
}
